package com.jcfk.eam.controller.main;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

import com.jcfk.eam.domain.query.main.EamInspectionPlanPersonQuery;
import com.jcfk.eam.domain.dto.main.EamInspectionPlanPersonDTO;
import com.jcfk.eam.service.main.EamInspectionPlanPersonService;

/**
 * 作业计划负责人
 *
 * @author awei
 * @email 522891237@gqq.com
 * @date 2024-09-24
 */
@Api(tags = {"作业计划负责人管理"})
@RestController
@RequestMapping("eaminspectionplanperson")
public class EamInspectionPlanPersonController {
    @Autowired
    private EamInspectionPlanPersonService eamInspectionPlanPersonService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<EamInspectionPlanPersonQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询作业计划负责人")
    @PostMapping("/queryByPage")
    public RetPage<EamInspectionPlanPersonDTO> queryByPage(@RequestBody ReqPageParam<EamInspectionPlanPersonQuery> requestParam) {
        DataPage<EamInspectionPlanPersonDTO> page = new DataPage<EamInspectionPlanPersonDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            EamInspectionPlanPersonDTO.class);
        page = eamInspectionPlanPersonService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     *  作业计划负责人
     * 根据id 查询详情
     */
    @ApiOperation("查询作业计划负责人")
    @GetMapping("/get/{id}")
    public RetResult<EamInspectionPlanPersonDTO> get(@PathVariable("id") String id) {
            EamInspectionPlanPersonDTO item = eamInspectionPlanPersonService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理作业计划负责人
     */
    @ApiOperation("保存作业计划负责人")
    @PostMapping("/save")
    @RequestLogHeader(modular = "作业计划负责人管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid EamInspectionPlanPersonDTO eamInspectionPlanPerson) {
        // 数据校验
        RetResult ret = eamInspectionPlanPersonService.isValid(eamInspectionPlanPerson);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(eamInspectionPlanPerson.getId())){
            // 新增
            eamInspectionPlanPersonService.insert(eamInspectionPlanPerson);
        } else{
            // 更新
            eamInspectionPlanPersonService.update(eamInspectionPlanPerson);
        }
        return RetResult.ok();

    }

    /**
     *  批量删除作业计划负责人
     */
    @ApiOperation("批量删除作业计划负责人")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "作业计划负责人管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody EamInspectionPlanPersonDTO eamInspectionPlanPerson) {
        return RetResult.ok(eamInspectionPlanPersonService.removeBigBatch(eamInspectionPlanPerson.getIds()));
    }





    /**
     *  删除作业计划负责人
     */
    @ApiOperation("删除作业计划负责人")
    @PostMapping("/deleteItem/{id}")
    @RequestLogHeader(modular = "作业计划负责人管理", businessType = "删除")
    public RetResult<?> deleteItem(@PathVariable("id") String id) {
        eamInspectionPlanPersonService.deleteItem(id);
        return RetResult.ok();
    }
}
